package com.jt.web.controller;

import com.fasterxml.jackson.databind.util.JSONPObject;
import com.jt.pojo.ItemDesc;
import com.jt.utils.ObjectMapperUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * jsonp测试
 * @author dc
 * @Classname JSONPController
 * @Date 2020/2/24 14:26
 */
@RestController
@RequestMapping("/web")
public class JSONPController {

    //@RequestMapping("/testJSONP")
    public String json01(String callback){
        ItemDesc itemDesc = new ItemDesc();
        itemDesc.setItemId(1000L).setItemDesc("jsonp测试");
        String json= ObjectMapperUtil.toJson(itemDesc);
        return callback+"("+json+")";
    }

    /**
     * JSONPObject是跨域访问的API
     * @param callback
     * @return
     */
   @RequestMapping("/testJSONP")
    public JSONPObject json02(String callback){
        ItemDesc itemDesc = new ItemDesc();
        itemDesc.setItemId(1000L).setItemDesc("jsonp测试");
        return new JSONPObject(callback,itemDesc);
    }
}
